package tech.eyao.hs60x.dto;

import java.io.Serializable;
import tech.eyao.hs60x.common.ReturnCode;
import tech.eyao.hs60x.enums.ExceptionCodeEnum;

public class BaseResult implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 4713265756635104591L;
    public Object             data;
    public int                code;
    public String             message;

    public BaseResult(int code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    /**
     * 构造方法
     * 
     * @param code
     * @param message
     * @param data
     */
    public BaseResult(int code, String message, Object data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 业务错误-包含CODE/MESSAG
     * 
     * @param code
     * @param message
     * @return
     */
    public static BaseResult isFailure(Integer code, String message) {
        return new BaseResult(code, message, null);
    }

    public static BaseResult isFailure(String message) {
        return new BaseResult(ExceptionCodeEnum.SYSTEM_EXCEPTION.getCode(), message, null);
    }
    /**
     * 
     * @param message
     * @return
     */
    public static BaseResult DELETE_EXCEPTION(String message) {
        return new BaseResult(ExceptionCodeEnum.DELETE_EXCEPTION.getCode(), message, null);
    }
    /**
     * UPDATE_EXCEPTION
     * @param message
     * @return
     */
    public static BaseResult UPDATE_EXCEPTION(String message) {
        return new BaseResult(ExceptionCodeEnum.UPDATE_EXCEPTION.getCode(), message, null);
    }
    /**
     * INSERT_EXCEPTION
     * @param message
     * @return
     */
    public static BaseResult INSERT_EXCEPTION(String message) {
        return new BaseResult(ExceptionCodeEnum.INSERT_EXCEPTION.getCode(), message, null);
    }
    /**
     * SELECT_EXCEPTION
     * @param message
     * @return
     */
    public static BaseResult SELECT_EXCEPTION(String message) {
        return new BaseResult(ExceptionCodeEnum.SELECT_EXCEPTION.getCode(), message, null);
    }
    /**
     * 常规性业务校验异常
     * 
     * @param message
     * @return
     */
    public static BaseResult isBussinessFail(String message) {
        return new BaseResult(ExceptionCodeEnum.INVALID_PARAMETER.getCode(), message, null);
    }

    /**
     * 默认系统级别异常
     * 
     * @return
     */
    public static BaseResult isDeFaultFailure() {
        return new BaseResult(ExceptionCodeEnum.SYSTEM_EXCEPTION.getCode(),
                ExceptionCodeEnum.SYSTEM_EXCEPTION.getMessage(), null);
    }

    /**
     * 默认系统级别异常
     * 
     * @return
     */
    public static BaseResult isDeFaultNoData() {
        return new BaseResult(ExceptionCodeEnum.RECORD_NOT_EXISTS.getCode(),
                ExceptionCodeEnum.RECORD_NOT_EXISTS.getMessage(), null);
    }

    /**
     * TOKEN 过期
     * 
     * @return
     */
    public static BaseResult isTokenExpire() {
        return new BaseResult(ExceptionCodeEnum.TOKEN_EXPIRE.getCode(), ExceptionCodeEnum.TOKEN_EXPIRE.getMessage(),
                null);
    }

    /**
     * TOKEN 过期
     * 
     * @return
     */
    public static BaseResult isTokenNull() {
        return new BaseResult(ExceptionCodeEnum.TOKEN_PARAMERROR_NULL.getCode(),
                ExceptionCodeEnum.TOKEN_PARAMERROR_NULL.getMessage(), null);
    }

    /**
     * 无结果成功
     * 
     * @return
     */
    public static BaseResult isSuccess() {
        return new BaseResult(ReturnCode.C_SUCCESS_CODE, ReturnCode.SUCCESS_CODE.getDesc(), null);
    }

    /**
     * 含结果成功
     * 
     * @param data
     * @return
     */
    public static BaseResult isSuccess(Object data) {
        return new BaseResult(ReturnCode.C_SUCCESS_CODE, ReturnCode.SUCCESS_CODE.getDesc(), data);
    }

    public BaseResult() {
        super();
    }

    @Override
    public String toString() {
        return "BaseResult [data=" + data + ", code=" + code + ", message=" + message + "]";
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}
